/** 抖动消除函数封装 截流执行, 例子：
 *   绑定监听query，截流执行，延迟200ms派发事件
 *   this.$watch('query', debounce((newQuery) => {
 *       this.$emit('query', newQuery);
 *   }, 200));
 **/
export function debounce (func, delay) {
    let timer;
    return function (...args) {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            func.apply(this, args);
        }, delay);
    };
}
